package com.hyp.mapper;

import com.hyp.pojo.Appointment;
import com.hyp.pojo.AppointmentDTO;
import com.hyp.pojo.Product;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AppointmentMapper {
    @Insert("insert into appointment (UserID, AppointmentType, AppointmentTime, AppointmentStatus, Notes, CreatedAt, UpdatedAt) " +
            "values (#{userId}, #{appointmentType}, #{appointmentTime}, #{appointmentStatus}, #{notes}, #{createdAt}, #{updatedAt})")
    void addAppoint(Appointment appointment);

    @Select("select * from appointment where  userId = #{userId} and appointmentStatus = #{appointmentStatus} order by appointmentTime desc")
    List<Appointment> appointlist(Integer userId,String appointmentStatus);

    @Select("select * from appointment where AppointmentID = #{appointmentId}")
    Appointment appointlistById(Integer appointmentId);

    @Update("update appointment set appointmentStatus = #{appointmentStatus},UpdatedAt = #{updatedAt} where AppointmentID = #{appointmentId}")
    void offappoint(Appointment appointment);

    @Select("SELECT * FROM product WHERE Description LIKE CONCAT('%', #{description}, '%')")
    List<Product> search(String description);

    @Select("SELECT a.AppointmentId , u.NickName, a.AppointmentTime,a.AppointmentType,a.Notes,a.UpdatedAt,a.AppointmentStatus " +
            "FROM appointment a JOIN user u ON a.UserID = u.UserID  " +
            "order by a.updatedAt DESC;")
    List<AppointmentDTO> allappointlist();

    @Update("update appointment set appointmentStatus = #{appointmentStatus},UpdatedAt = #{updatedAt} where AppointmentID = #{appointmentId}")
    void finishappoint(Appointment appointment);
}
